package com.kanq.service.designpatterns.strategy;

import java.lang.reflect.Array;
import java.util.Arrays;

/**
 * @Author cheng jun
 * @Description: 开闭原则：修改关闭，扩展打开
 * @Date 2021/7/13 21:24
 */
public class SortDemo {

    public static void sort(CompareTo[] array) {
        //需进行length-1次冒泡
        for(int i = 0; i < array.length - 1; i++) {
            for(int j = 0; j < array.length - 1 - i; j++) {
                if(array[j].compareTo(array[j + 1]) == 1) {
                    CompareTo temp = array[j];
                    array[j] = array[j + 1];
                    array[j + 1] = temp;
                }
            }
        }
    }

    public static void main(String[] args) {
        Dog[] array = {new Dog(3), new Dog(1), new Dog(5)};
        SortDemo.sort(array);
        System.out.println(Arrays.toString(array));
    }
}


